import axios,{Axios} from 'axios';

import VueRouter from "vue-router";
import Vue from "vue";
Vue.use(VueRouter);

var myrouter = new VueRouter({
	routes:[
		
	]
});

myrouter.beforeEach(function(to, from, next){
	if(to.path == '/login'){
		next();
	}else{
		//验证只有合法登录才放行
		const token = localStorage.getItem("token");
		//异步校验令牌是否合法
		  axios({
			  url:"/tenant/verify",
			  method:"get",
			  headers:{
				  token:token
			  }
		  }).then(res=>{
			if(res.data.code == 0){
			  next();
			}else{
			  next('/product?redirect=${to.path}')
			}
		  });
	}
});

export default myrouter;